<%inherit file="base.html"/>
<%def name="head()">
<script src="/static/js/bootstrap-datepicker.js"></script>
<link rel="stylesheet" href="/static/js/datepicker.css"> 
<script>


function productCalc(){
    param = {
        'months': $("#months").val() || 0,
        'product_id':$("#product_id").val(),
        'giftdays':$("#giftdays").val(),
        '_xsrf': '${handler.xsrf_token}'
    }
    $.post("/admin/account/opencalc", param, function (ev) {
        console.log(ev);
        if(ev.code==0){
            console.log(ev.data);
            $("#fee_value").val(ev.data.fee_value);
            $("#expire_date").val(ev.data.expire_date);
            if(ev.data.policy == 0){
               $("#months").parent().parent().show();
            }else{
               $("#months").val(0);
               $("#months").parent().parent().hide();
            }
        }
    }, "json");
}

function check_samename()
{
    if($("#is_samename_").is(':checked')){
        $("#customer_name").parent().parent().show();
        $("#customer_password").parent().parent().show();
    }
    else{
        $("#customer_name").parent().parent().hide();
        $("#customer_password").parent().parent().hide();
    }
}

function reBuildAccount(){
    $.get("/admin/customer/account/build", function (ev) {
        console.log(ev);
        if(ev.code==0){
            console.log(ev);
            $("#account_number").val(ev.account);
            $("#password").val(ev.passwd);
        }
    }, "json");
}

//页面初始化
$(document).ready(function (){
    // $("#expire_date").datepicker();
    $('#product_id').change(function() {
        productCalc();
    });
    $('#months').blur(function() {
        productCalc();
    });    
    $('#giftdays').blur(function() {
        productCalc();
    });    
    check_samename();
    $("#is_samename_").click(function(){
        check_samename();
    });
    reBuildAccount();  
});
</script>

</%def>
<%def name="body()">
<section class="content">
    <div class="box box-primary">
        <div class="box-header">
            <i class="fa fa-user-plus"></i>
            <h3 class="box-title">${form.title}</h3>
            <div class="bar pull-right"><a href="javascript:history.go(-1);">返回</a></div>
        </div>
        <div class="box-body">
            <div class="container">
            % if msg:
            <div class="alert alert-warning">${msg}</div>
            % endif
            <form class="form-horizontal form-well" role="form" action="${form.action}" method="post">
            ${xsrf_form_html()}
            ${form.render_css()}
        </form>
    </div>
</div>
</div>
    </section>
</%def>